package com.onlineshop.highgee.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.onlineshop.highgee.dao.MyOrderDao;
import com.onlineshop.highgee.daoimpl.MyOrderDaoImpl;
import com.onlineshop.highgee.entity.MyOrder;



/**
 * Servlet implementation class WhetherLogServlet
 */
@WebServlet("/WhetherLogServlet")
public class WhetherLogServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession session = request.getSession(true);
		String userName = (String) session.getAttribute("user_name");
		try {
			if (userName !=null) {
				MyOrderDao myOrderDao = new MyOrderDaoImpl();
				List<MyOrder> list = new ArrayList<MyOrder>();
				list = myOrderDao.findByUserName(userName);
				session.setAttribute("list", list);
				RequestDispatcher dispatcher = request.getRequestDispatcher("myorder.jsp");
				dispatcher.forward(request, response);
			}else {
				RequestDispatcher dispatcher = request.getRequestDispatcher("myaccount.jsp");
				dispatcher.forward(request, response);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
